package ptij.vocoder.baseModel.lp_analysis;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// Lsp_Old_Init
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class Lsp_Old_Init extends TypedAtomicActor {

    public Lsp_Old_Init(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        input = new TypedIOPort(this, "input", true, false);
        input.setTypeEquals(BaseType.OBJECT);

        reset = new TypedIOPort(this, "reset", true, false);
        reset.setTypeEquals(BaseType.BOOLEAN); 

        output = new TypedIOPort(this, "output", false, true);
        output.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort input;
    public TypedIOPort reset;

    // Output Ports
    public TypedIOPort output;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
        _init();
    }

    public void fire() throws IllegalActionException {
        if(reset.hasToken(0)) {
            reset.get(0);
            _init();
        }
        output.broadcast(new ObjectToken(_lsp_old));

        if(input.hasToken(0)) {
            ObjectToken obj = (ObjectToken) input.get(0);
            _lsp_old = (Short []) obj.getValue();
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private void _init() {
        _lsp_old = new Short[Cnst.M];
        _lsp_old[0] = new Short((short)30000);
        _lsp_old[1] = new Short((short)26000);
        _lsp_old[2] = new Short((short)21000);
        _lsp_old[3] = new Short((short)15000);
        _lsp_old[4] = new Short((short)8000);
        _lsp_old[5] = new Short((short)0);
        _lsp_old[6] = new Short((short)-8000);
        _lsp_old[7] = new Short((short)-15000);
        _lsp_old[8] = new Short((short)-21000);
        _lsp_old[9] = new Short((short)-26000);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private Short [] _lsp_old;
}
